package comlanka.server;

import java.util.logging.Logger;

import comlanka.PMF;

import javax.jdo.PersistenceManager;

import comlanka.UserName;
import comlanka.client.GreetingService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * The server side implementation of the RPC service.
 */
@SuppressWarnings( "serial" )
public class GreetingServiceImpl extends RemoteServiceServlet implements
		GreetingService
{

	private static final Logger logger = Logger
			.getLogger(GreetingServiceImpl.class.getName());

	public String greetServer( String input )
	{
		String error = "";
		UserName userName = new UserName();
		userName.setUser(input);

		PersistenceManager pm = PMF.get().getPersistenceManager();
		try
		{
			pm.makePersistent(userName);
		}
		catch (Exception e)
		{
			error = e.toString();
			logger.severe(error);
		}
		finally
		{
			pm.close();
		}
		String serverInfo = getServletContext().getServerInfo();
		String userAgent = getThreadLocalRequest().getHeader("User-Agent");
		return "Hello, " + input + "!<br><br>I am running " + serverInfo
				+ ".<br><br>It looks like you are using:<br>" + userAgent
				+ "<br>" + error;
	}
}
